//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using EntLibContrib.Resource.Configuration;
using EntLibContrib.Resource.Providers;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Tests
{
	[TestClass]
	public class DataResourceProviderFixture
	{
		private static Database database;
		private static string baseName;

		[ClassInitialize]
#if NUNIT
		public void CreateResource ()
#else
		public static void CreateResource (TestContext context)
#endif
		{
			TestDataResources.Create();
			database = TestDataResources.Database;
			baseName = TestDataResources.BaseName;
		}

		[TestMethod]
		public void CanInitializeResourceProviderFromConfigurationObjects ()
		{
			DataResourceProvider dataResourceProvider = new DataResourceProvider(database, baseName);
			System.Resources.ResourceManager resourceManager = dataResourceProvider.CreateResourceManager();

			Assert.IsNotNull(resourceManager, "The resource manager should now exist");
			Assert.AreEqual("e-World Developments Ltd", resourceManager.GetString("Ewdev"), "We should now be able to read resources");
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void NullDatabaseThrowsException()
		{
			DataResourceProvider dataResourceProvider = new DataResourceProvider(null, baseName);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void NullBaseNameThrowsException()
		{
			DataResourceProvider dataResourceProvider = new DataResourceProvider(database, null);
		}
	}
}
